//
//  TabController.m
//  zhinengfeixing
//
//  Created by hff on 16/2/29.
//  Copyright © 2016年 threeTi. All rights reserved.
//

#import "TabBarController.h"
#import "TTINavigationController.h"
#import "ICUser.h"
#import "UIColor+Utils.h"
#import "HUD.h"
#import "AppMacro.h"
#import "UIImage+Utils.h"

@interface TabBarController ()<UITabBarControllerDelegate,UITabBarDelegate>

@end

@implementation TabBarController
- (void)viewDidLoad {
    [super viewDidLoad];

    
    //设置首页
    UIStoryboard *home = [UIStoryboard storyboardWithName:@"TTIHome" bundle:nil];
    TTINavigationController *homeNav1 = [home instantiateInitialViewController];
    
    //云学堂
    UIStoryboard *classificaiton = [UIStoryboard storyboardWithName:@"TTICloudSchool" bundle:nil];
    TTINavigationController *homeNav2 = [classificaiton instantiateInitialViewController];
    
    //播库
    UIStoryboard *communtiy = [UIStoryboard storyboardWithName:@"TTIVideoLibrary" bundle:nil];
    TTINavigationController *homeNav3 = [communtiy instantiateInitialViewController];
    
    //工具
    UIStoryboard *shopCar = [UIStoryboard storyboardWithName:@"TTITools" bundle:nil];
    TTINavigationController *homeNav4 = [shopCar instantiateInitialViewController];
    
    //个人中心
    UIStoryboard *person = [UIStoryboard storyboardWithName:@"TTIPerson" bundle:nil];
    TTINavigationController *homeNav5 = [person instantiateInitialViewController];
    
    
    NSArray *controllers = @[homeNav1,homeNav2,homeNav3,homeNav4,homeNav5];
    self.viewControllers = controllers;
    
    

    UITabBarItem *tabBarItem1 = [self createWithTitle:@"首页" image:@"ic_home" seletedImage:@"ic_home_sel"];
    UITabBarItem *tabBarItem2 = [self createWithTitle:@"云学堂" image:@"ic_select" seletedImage:@"ic_select_sel"];
    UITabBarItem *tabBarItem3 = [self createWithTitle:@"播库" image:@"ic_classify" seletedImage:@"ic_classify_sel"];
    UITabBarItem *tabBarItem4 = [self createWithTitle:@"工具" image:@"ic_shop" seletedImage:@"ic_shop_sel"];
    UITabBarItem *tabBarItem5 = [self createWithTitle:@"我的" image:@"ic_profile" seletedImage:@"ic_profile_sel"];

    
    
    //修改tabbar图片偏移
//    tabBarItem1.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
//    tabBarItem2.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
//    tabBarItem3.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);

    // 设置文字的样式
  
    homeNav1.tabBarItem = tabBarItem1;
    homeNav2.tabBarItem = tabBarItem2;
    homeNav3.tabBarItem = tabBarItem3;
    homeNav4.tabBarItem = tabBarItem4;
    homeNav5.tabBarItem = tabBarItem5;
    self.delegate = self;
    
    
    //去掉tabbar顶部黑线
  [self.tabBar setBackgroundImage:[UIImage createImageWithColor:[UIColor whiteColor]]];
    self.tabBar.translucent = NO;

   [self.tabBar setShadowImage:[[UIImage alloc] init]];
  
}
- (UITabBarItem *)createWithTitle:(NSString *)title image:(NSString *)image seletedImage:(NSString *)selectedImage
{
    UITabBarItem *barItem = [[UITabBarItem alloc]initWithTitle:title image:[[UIImage imageNamed:image]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor colorForHex:@"666666"];
   textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor colorForHex:@"ed3c2d"];
    selectTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    [barItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [barItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    return barItem;
}

-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
//    if (viewController == (UIViewController *)[tabBarController.viewControllers objectAtIndex:2]  && ![ICUser isLogin])
//    {
//        
//       NOTLOGIN_ALERT
//        
//       return NO;
//    }

    
    return YES;
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
}

@end
